/*
 * Copyright (c) 2015—2030 GantSoftware.Co.Ltd. All rights reserved.
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * is not allowed to be distributed or copied without the license from
 * GantSoftware.Co.Ltd. Please contact the company for more information.
 */
package com.gantang.poc.req;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.util.List;
import java.util.Set;

@Data
@EqualsAndHashCode(callSuper = true)
public class ProFeatureTable extends TaskIdReq {
    @Valid
    @NotNull(message = "产品特征清单不能为空")
    private List<FeatureTableData> featureTableDatas; //产品特征清单
    @Valid
    @NotNull(message = "约束关系不能为空")
    private List<RuleData> ruleDatas; //约束关系
    private String callBackUrl; //通知编译结果的回调地址

    @Schema(description = "变型产品编码集合", hidden = true)
    private Set<String> configNodeCodes;

    @Data
    public static class FeatureTableData {
        @NotBlank(message = "特征族编码不能为空")
        private String featureFamily;
        @NotBlank(message = "特征值编码不能为空")
        private String featureCode;
        @Min(value = 0, message = "权重必须是正整数")
        private Integer weight;
    }

    @Data
    public static class RuleData {
        @NotBlank(message = "约束类型不能为空")
        @Pattern(regexp = "[01]",
                message = "约束类型不能为空,约束类型必须是以下之一：" +
                        "0 (整车约束); " +
                        "1 (配置约束).")
        private String ruleType;
        @NotBlank(message = "约束条件表达式不能为空")
        private String ruleExpression;
        @NotBlank(message = "约束结果表达式不能为空")
        private String ruleResult;
        @NotBlank(message = "规则约束类型不能为空")
        @Pattern(regexp = "inclusion|default|available|exclusion",
                message = "规则约束类型不能为空,规则约束类型必须是以下之一：" +
                        "inclusion (标配-条件为真时，结果一定为真); " +
                        "default (默认选装-条件为真时，结果可选); " +
                        "available (可选-条件为真时，结果可选);" +
                        "exclusion (不配-条件为真时，结果一定为假).")
        private String constraintType;
    }
}
